* Bring in data from Lucid experiment
use climate_study.dta, clear

* Create Party ID Scale
gen pid7=1 if political_party=="1"
replace pid7=2 if political_party=="2"
replace pid7=3 if political_party=="3" | political_party=="6"
replace pid7=4 if political_party=="4"
replace pid7=5 if political_party=="5" | political_party=="8"
replace pid7=6 if political_party=="9"
replace pid7=7 if political_party=="10"
replace pid7=8 if political_party=="7"

recode pid7 1/3=1 4=2 5/7=3 8=2, gen(partyid)
label define partyid 1 "Democrats" 2 "Ind/other" 3 "Republicans"
label values partyid partyid

* Create variable indicating condition
encode random, gen(condition)
recode condition 4=3 3=4
label define cond 1 "Control" 2 "Local info" 3 "Party logos" 4 "Both"
label values condition cond

recode condition 1=0 2=1 3=0 4=1, gen(localtreat)
recode condition 1=0 2=0 3/4=1, gen(partytreat)

* Scale policy items
recode policygrid_* (2=0)
irt grm policygrid_* climate
predict policy, latent
replace policy=((policy*-1)+1.604572)/2.641398
twoway histogram policy, percent aspect(1) title("Pro-climate policy scale", size(medlarge)) xtitle("Value") saving(policy, replace) 

* Scale actions items
recode actionstaken_* (1/2=1) (3=0)
irt 2pl actionstaken_*
predict act, latent
replace act=(act+1.592673)/2.652552
twoway histogram act, percent aspect(1) title("Personal climate actions scale", size(medlarge)) xtitle("Value") saving(action, replace) 

graph combine policy.gph action.gph, ycom
graph export dist.pdf, replace


* Main treatment effects (by each condition)

reg act i.condition
margins, over(condition) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Climate actions scale", size(medlarge)) aspect(1) ciop(msize(0)) saving(actions, replace)

reg policy i.condition
margins, over(condition) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Policy scale", size(medlarge)) aspect(1) ciop(msize(0)) saving(policy, replace)

graph combine policy.gph actions.gph, ycom
graph export effects.pdf, replace



* Test for difference in distributions 

* Policy: Control vs. local info
ksmirnov policy if condition<3, by(condition)

* Policy: Control vs. party
ksmirnov policy if condition==1 | condition==3, by(condition)

* Actions: Control vs. local info
ksmirnov act if condition<3, by(condition)

* Actiions: Control vs. party
ksmirnov act if condition==1 | condition==3, by(condition)


* By partisanship

reg act i.condition if partyid==1
margins, over(condition partyid) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Democrats", size(medlarge)) aspect(1) ciop(msize(0)) saving(dem, replace)
reg act i.condition if partyid==2
margins, over(condition partyid) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Independents/other", size(medlarge)) aspect(1) ciop(msize(0)) saving(ind, replace)
reg act i.condition if partyid==3
margins, over(condition partyid) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Republicans", size(medlarge)) aspect(1) ciop(msize(0)) saving(rep, replace)

graph combine dem.gph ind.gph rep.gph, ycom title("Climate actions scale", size(large)) row(1) saving(act, replace)

reg policy i.condition if partyid==1
margins, over(condition partyid) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Democrats", size(medlarge)) aspect(1) ciop(msize(0)) saving(dem, replace)
reg policy i.condition if partyid==2
margins, over(condition partyid) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Independents/other", size(medlarge)) aspect(1) ciop(msize(0)) saving(ind, replace)
reg policy i.condition if partyid==3
margins, over(condition partyid) 
marginsplot,  xlabel(.5 " " 1 "Control" 2 "Local info" 3 "Party labels" 4 "Both" 4.5 " ", notick nogrid) ///
	 plotop(lc(none) msymbol(O)) xtitle("") ytitle("Average value on scale") ylabel(.4 .5 .6 .7 .8) ///
	title("Republicans", size(medlarge)) aspect(1) ciop(msize(0)) saving(rep, replace)

graph combine dem.gph ind.gph rep.gph, ycom title("Policy scale", size(large)) row(1) saving(policy, replace)

graph combine policy.gph act.gph , col(1) iscale(.7)
graph export bypid.pdf, replace


* Re-create results including control variables

* Re-coding of control variables
destring education, replace
destring gender, replace
destring ethnicity, replace
destring hispanic, replace

gen race4=1 if ethnicity==1 & hispanic==1
replace race4=2 if ethnicity==2
replace race4=3 if hispanic>1
replace race4=4 if race4==.

label define race 1 "White" 2 "Black" 3 "Hispanic" 4 "Other"
label values race4 race

recode education -3105=. 1/2=1 3/5=2 6=3 7/8=4, gen(educ4)
recode gender 1=0 2=1, gen(female)
recode kids18 2=0

* Run models

reg act i.condition educ4 female age kids18  attend ib2.urbancity ib4.race4 egal_equal ib2.partyid 
reg policy i.condition educ4 female age kids18  attend ib2.urbancity ib4.race4 egal_equal ib2.partyid 

